package org.hl7.fhir.r5.test.profiles.codegen;

import java.util.List;
import java.util.ArrayList;
import javax.annotation.Nullable;
import java.util.Date;


import org.hl7.fhir.r5.context.IWorkerContext;
import org.hl7.fhir.r5.model.*;
import org.hl7.fhir.r5.profilemodel.PEBuilder;
import org.hl7.fhir.r5.profilemodel.PEInstance;
import org.hl7.fhir.r5.profilemodel.PEBuilder.PEElementPropertiesPolicy;
import org.hl7.fhir.r5.profilemodel.gen.PEGeneratedBase;
import org.hl7.fhir.r5.profilemodel.gen.Min;
import org.hl7.fhir.r5.profilemodel.gen.Max;
import org.hl7.fhir.r5.profilemodel.gen.Label;
import org.hl7.fhir.r5.profilemodel.gen.Doco;
import org.hl7.fhir.r5.profilemodel.gen.BindingStrength;
import org.hl7.fhir.r5.profilemodel.gen.ValueSet;
import org.hl7.fhir.r5.profilemodel.gen.MustSupport;
import org.hl7.fhir.r5.profilemodel.gen.Definition;


// Generated by the HAPI Java Profile Generator, 5/11/24, 6:00 pm

/**
 * Regulatory approval, clearance or licencing related to a regulated product, 
 * treatment, facility or activity that is cited in a guidance, regulation, rule or 
 * legislative act. An example is Market Authorization relating to a Medicinal 
 * Product.
 *
 */
public class RegulatedAuthorizationUvEpi extends PEGeneratedBase {

  public static final String CANONICAL_URL = "http://hl7.org/fhir/uv/emedicinal-product-info/StructureDefinition/RegulatedAuthorization-uv-epi|1.0.0";

  @Min("0") @Max("1") @Doco("")
  private String id;  // 

  @Min("0") @Max("*") @Doco("Additional content defined by implementations")
  @Definition("May be used to represent additional information that is not part of the basic definition of the resource. To make the use of extensions safe and managable, there is a strict set of governance applied to the definition and use of extensions. Though any implementer can define an extension, there is a set of requirements that SHALL be met as part of the definition of the extension.")
  private List<Extension> extensions = new ArrayList<>();  // Additional content defined by implementations

  @Min("0") @Max("*") @Doco("Extensions that cannot be ignored")
  @Definition("May be used to represent additional information that is not part of the basic definition of the resource and that modifies the understanding of the element that contains it and/or the understanding of the containing element's descendants. Usually modifier elements provide negation or qualification. To make the use of extensions safe and managable, there is a strict set of governance applied to the definition and use of extensions. Though any implementer is allowed to define an extension, there is a set of requirements that SHALL be met as part of the definition of the extension. Applications processing a resource are required to check for modifier extensions.\n\nModifier extensions SHALL NOT change the meaning of any elements on Resource or DomainResource (including cannot change the meaning of modifierExtension itself).")
  private List<Extension> modifierExtensions = new ArrayList<>();  // Extensions that cannot be ignored

  @Min("1") @Max("*") @Doco("Identifier assigned by the health authority to a single medicinal product")
  @Definition("Business identifier for the authorization, typically assigned by the authorizing body.")
  private List<Identifier> identifiers = new ArrayList<>();// @NotNull  // Identifier assigned by the health authority to a single medicinal product

  @Min("1") @Max("*") @Doco("The product type, treatment, facility or activity that is being authorized")
  @Definition("The product type, treatment, facility or activity that is being authorized.")
  private List<Reference> subjects = new ArrayList<>();// @NotNull  // The product type, treatment, facility or activity that is being authorized

  @Min("0") @Max("1") @Doco("The time period in which the regulatory approval etc. is in effect, e.g. a Marketing Authorization includes the date of authorization and/or expiration date")
  @Definition("The time period in which the regulatory approval, clearance or licencing is in effect. As an example, a Marketing Authorization includes the date of authorization and/or an expiration date.")
  private Period validityPeriod;  // The time period in which the regulatory approval etc. is in effect, e.g. a Marketing Authorization includes the date of authorization and/or expiration date

  @Min("0") @Max("*") @Doco("Reference to the Clinical Use Definition")
  @Definition("Condition for which the use of the regulated product applies.")
  private List<CodeableReference> indications = new ArrayList<>();  // Reference to the Clinical Use Definition

  @Min("1") @Max("1") @Doco("The organization that has been granted this authorization, by the regulator")
  @Definition("The organization that has been granted this authorization, by some authoritative body (the 'regulator').")
  private Reference holder;// @NotNull  // The organization that has been granted this authorization, by the regulator

  @Min("0") @Max("1") @Doco("The regulatory authority or authorizing body granting the authorization")
  @Definition("The regulatory authority or authorizing body granting the authorization. For example, European Medicines Agency (EMA), Food and Drug Administration (FDA), Health Canada (HC), etc.")
  private Reference regulator;  // The regulatory authority or authorizing body granting the authorization

  @Min("0") @Max("*") @Doco("Additional information or supporting documentation about the authorization")
  @Definition("Additional information or supporting documentation about the authorization.")
  private List<Reference> attachedDocuments = new ArrayList<>();  // Additional information or supporting documentation about the authorization

  @Min("0") @Max("1") @Doco("The case or regulatory procedure for granting or amending a regulated authorization. Note: This area is subject to ongoing review and the workgroup is seeking implementer feedback on its use (see link at bottom of page)")
  @Definition("The case or regulatory procedure for granting or amending a regulated authorization. An authorization is granted in response to submissions/applications by those seeking authorization. A case is the administrative process that deals with the application(s) that relate to this and assesses them. Note: This area is subject to ongoing review and the workgroup is seeking implementer feedback on its use (see link at bottom of page).")
  private BackboneElement _case;  // The case or regulatory procedure for granting or amending a regulated authorization. Note: This area is subject to ongoing review and the workgroup is seeking implementer feedback on its use (see link at bottom of page)


  /**
   * Parameter-less constructor.
   *
   */
  public RegulatedAuthorizationUvEpi() {
  }

  /**
   * Construct an instance of the object, and fill out all the fixed values 
   *
   */
  public RegulatedAuthorizationUvEpi(IWorkerContext context) {
    workerContext = context;
    PEBuilder builder = new PEBuilder(context, PEElementPropertiesPolicy.EXTENSION, true);
    PEInstance src = builder.buildPEInstance(CANONICAL_URL, builder.createResource(CANONICAL_URL, false));
    load(src);
  }

  /**
   * Populate an instance of the object based on this source object 
   *
   */
  public static RegulatedAuthorizationUvEpi fromSource(IWorkerContext context, RegulatedAuthorization source) {
    RegulatedAuthorizationUvEpi theThing = new RegulatedAuthorizationUvEpi();
    theThing.workerContext = context;
    PEBuilder builder = new PEBuilder(context, PEElementPropertiesPolicy.EXTENSION, true);
    PEInstance src = builder.buildPEInstance(CANONICAL_URL, source);
    theThing.load(src);
    return theThing;
  }


  public void load(PEInstance src) {
    clear();
    if (src.hasChild("id")) {
      id = ((IdType) src.child("id").asDataType()).getValue();
    }
    for (PEInstance item : src.children("extension")) {
      extensions.add((Extension) item.asDataType());
    }
    for (PEInstance item : src.children("modifierExtension")) {
      modifierExtensions.add((Extension) item.asDataType());
    }
    for (PEInstance item : src.children("identifier")) {
      identifiers.add((Identifier) item.asDataType());
    }
    for (PEInstance item : src.children("subject")) {
      subjects.add((Reference) item.asDataType());
    }
    if (src.hasChild("validityPeriod")) {
      validityPeriod = (Period) src.child("validityPeriod").asDataType();
    }
    for (PEInstance item : src.children("indication")) {
      indications.add((CodeableReference) item.asDataType());
    }
    if (src.hasChild("holder")) {
      holder = (Reference) src.child("holder").asDataType();
    }
    if (src.hasChild("regulator")) {
      regulator = (Reference) src.child("regulator").asDataType();
    }
    for (PEInstance item : src.children("attachedDocument")) {
      attachedDocuments.add((Reference) item.asDataType());
    }
    if (src.hasChild("case")) {
      _case = (BackboneElement) src.child("case").asElement();
    }

  }

  /**
   * Build a instance of the underlying object based on this wrapping object 
   *
   */
  public RegulatedAuthorization build(IWorkerContext context) {
    workerContext = context;
    return build();
  }

  /**
   * Build a instance of the underlying object based on this wrapping object 
   *
   */
  public RegulatedAuthorization build() {
    RegulatedAuthorization theThing = new RegulatedAuthorization();
    PEBuilder builder = new PEBuilder(workerContext, PEElementPropertiesPolicy.EXTENSION, true);
    PEInstance tgt = builder.buildPEInstance(CANONICAL_URL, theThing);
    save(tgt, false);
    return theThing;
  }

  /**
   * Save this profile class into an existing resource (overwriting anything that 
   * exists in the profile) 
   *
   */
  public void save(IWorkerContext context, RegulatedAuthorization dest, boolean nulls) {
    workerContext = context;
    PEBuilder builder = new PEBuilder(context, PEElementPropertiesPolicy.EXTENSION, true);
    PEInstance tgt = builder.buildPEInstance(CANONICAL_URL, dest);
    save(tgt, nulls);
  }

  public void save(PEInstance tgt, boolean nulls) {
    tgt.clear("id");
    if (id != null) {
      tgt.makeChild("id").data().setProperty("value", new IdType(id));
    }
    tgt.clear("extension");
    for (Extension item : extensions) {
      tgt.addChild("extension", item);
    }
    tgt.clear("modifierExtension");
    for (Extension item : modifierExtensions) {
      tgt.addChild("modifierExtension", item);
    }
    tgt.clear("identifier");
    for (Identifier item : identifiers) {
      tgt.addChild("identifier", item);
    }
    tgt.clear("subject");
    for (Reference item : subjects) {
      tgt.addChild("subject", item);
    }
    tgt.clear("validityPeriod");
    if (validityPeriod != null) {
      tgt.addChild("validityPeriod", validityPeriod);
    }
    tgt.clear("indication");
    for (CodeableReference item : indications) {
      tgt.addChild("indication", item);
    }
    tgt.clear("holder");
    if (holder != null) {
      tgt.addChild("holder", holder);
    }
    tgt.clear("regulator");
    if (regulator != null) {
      tgt.addChild("regulator", regulator);
    }
    tgt.clear("attachedDocument");
    for (Reference item : attachedDocuments) {
      tgt.addChild("attachedDocument", item);
    }
    tgt.clear("case");
    if (_case != null) {
      tgt.addChild("case", _case);
    }

  }

  public String getId() {
    return id;
  }

  public RegulatedAuthorizationUvEpi setId(String value) {
    this.id = value;
    return this;
  }

  public boolean hasId() {
    return id != null;
  }

  /**
   * May be used to represent additional information that is not part of the basic 
   * definition of the resource. To make the use of extensions safe and managable, 
   * there is a strict set of governance applied to the definition and use of 
   * extensions. Though any implementer can define an extension, there is a set of 
   * requirements that SHALL be met as part of the definition of the extension.
   *
   */
  public List<Extension> getExtensions() {
    if (extensions == null) { extensions = new ArrayList<>(); }
    return extensions;
  }

  public boolean hasExtensions() {
    return extensions != null && !extensions.isEmpty();
  }

  public Extension addExtension() {
    Extension theThing = new Extension();
    getExtensions().add(theThing);
    return theThing;
  }

  public boolean hasExtension(Extension item) {
    return hasExtensions() && extensions.contains(item);
  }

  public void removeExtension(Extension item) {
    if (hasExtension(item)) {
      extensions.remove(item);
    }
  }


  /**
   * May be used to represent additional information that is not part of the basic 
   * definition of the resource and that modifies the understanding of the element 
   * that contains it and/or the understanding of the containing element's 
   * descendants. Usually modifier elements provide negation or qualification. To 
   * make the use of extensions safe and managable, there is a strict set of 
   * governance applied to the definition and use of extensions. Though any 
   * implementer is allowed to define an extension, there is a set of requirements 
   * that SHALL be met as part of the definition of the extension. Applications 
   * processing a resource are required to check for modifier extensions.
   *
   * 
   *
   * Modifier extensions SHALL NOT change the meaning of any elements on Resource or 
   * DomainResource (including cannot change the meaning of modifierExtension 
   * itself).
   *
   */
  public List<Extension> getModifierExtensions() {
    if (modifierExtensions == null) { modifierExtensions = new ArrayList<>(); }
    return modifierExtensions;
  }

  public boolean hasModifierExtensions() {
    return modifierExtensions != null && !modifierExtensions.isEmpty();
  }

  public Extension addModifierExtension() {
    Extension theThing = new Extension();
    getModifierExtensions().add(theThing);
    return theThing;
  }

  public boolean hasModifierExtension(Extension item) {
    return hasModifierExtensions() && modifierExtensions.contains(item);
  }

  public void removeModifierExtension(Extension item) {
    if (hasModifierExtension(item)) {
      modifierExtensions.remove(item);
    }
  }


  /**
   * Business identifier for the authorization, typically assigned by the authorizing 
   * body.
   *
   */
  public List<Identifier> getIdentifiers() {
    if (identifiers == null) { identifiers = new ArrayList<>(); }
    return identifiers;
  }

  public boolean hasIdentifiers() {
    return identifiers != null && !identifiers.isEmpty();
  }

  public Identifier addIdentifier() {
    Identifier theThing = new Identifier();
    getIdentifiers().add(theThing);
    return theThing;
  }

  public boolean hasIdentifier(Identifier item) {
    return hasIdentifiers() && identifiers.contains(item);
  }

  public void removeIdentifier(Identifier item) {
    if (hasIdentifier(item)) {
      identifiers.remove(item);
    }
  }


  /**
   * The product type, treatment, facility or activity that is being authorized.
   *
   */
  public List<Reference> getSubjects() {
    if (subjects == null) { subjects = new ArrayList<>(); }
    return subjects;
  }

  public boolean hasSubjects() {
    return subjects != null && !subjects.isEmpty();
  }

  public Reference addSubject() {
    Reference theThing = new Reference();
    getSubjects().add(theThing);
    return theThing;
  }

  public boolean hasSubject(Reference item) {
    return hasSubjects() && subjects.contains(item);
  }

  public void removeSubject(Reference item) {
    if (hasSubject(item)) {
      subjects.remove(item);
    }
  }


  /**
   * The time period in which the regulatory approval, clearance or licencing is in 
   * effect. As an example, a Marketing Authorization includes the date of 
   * authorization and/or an expiration date.
   *
   */
  public Period getValidityPeriod() {
    if (validityPeriod == null) { validityPeriod = new Period(); }
    return validityPeriod;
  }

  public RegulatedAuthorizationUvEpi setValidityPeriod(Period value) {
    this.validityPeriod = value;
    return this;
  }
  public boolean hasValidityPeriod() {
    return validityPeriod != null;
  }

  /**
   * Condition for which the use of the regulated product applies.
   *
   */
  public List<CodeableReference> getIndications() {
    if (indications == null) { indications = new ArrayList<>(); }
    return indications;
  }

  public boolean hasIndications() {
    return indications != null && !indications.isEmpty();
  }

  public CodeableReference addIndication() {
    CodeableReference theThing = new CodeableReference();
    getIndications().add(theThing);
    return theThing;
  }

  public boolean hasIndication(CodeableReference item) {
    return hasIndications() && indications.contains(item);
  }

  public void removeIndication(CodeableReference item) {
    if (hasIndication(item)) {
      indications.remove(item);
    }
  }


  /**
   * The organization that has been granted this authorization, by some authoritative 
   * body (the 'regulator').
   *
   */
  public Reference getHolder() {
    if (holder == null) { holder = new Reference(); }
    return holder;
  }

  public RegulatedAuthorizationUvEpi setHolder(Reference value) {
    this.holder = value;
    return this;
  }
  public boolean hasHolder() {
    return holder != null;
  }

  /**
   * The regulatory authority or authorizing body granting the authorization. For 
   * example, European Medicines Agency (EMA), Food and Drug Administration (FDA), 
   * Health Canada (HC), etc.
   *
   */
  public Reference getRegulator() {
    if (regulator == null) { regulator = new Reference(); }
    return regulator;
  }

  public RegulatedAuthorizationUvEpi setRegulator(Reference value) {
    this.regulator = value;
    return this;
  }
  public boolean hasRegulator() {
    return regulator != null;
  }

  /**
   * Additional information or supporting documentation about the authorization.
   *
   */
  public List<Reference> getAttachedDocuments() {
    if (attachedDocuments == null) { attachedDocuments = new ArrayList<>(); }
    return attachedDocuments;
  }

  public boolean hasAttachedDocuments() {
    return attachedDocuments != null && !attachedDocuments.isEmpty();
  }

  public Reference addAttachedDocument() {
    Reference theThing = new Reference();
    getAttachedDocuments().add(theThing);
    return theThing;
  }

  public boolean hasAttachedDocument(Reference item) {
    return hasAttachedDocuments() && attachedDocuments.contains(item);
  }

  public void removeAttachedDocument(Reference item) {
    if (hasAttachedDocument(item)) {
      attachedDocuments.remove(item);
    }
  }


  /**
   * The case or regulatory procedure for granting or amending a regulated 
   * authorization. An authorization is granted in response to 
   * submissions/applications by those seeking authorization. A case is the 
   * administrative process that deals with the application(s) that relate to this 
   * and assesses them. Note: This area is subject to ongoing review and the 
   * workgroup is seeking implementer feedback on its use (see link at bottom of 
   * page).
   *
   */
  public @Nullable BackboneElement get_case() { // BackboneElement is abstract 
    return _case;
  }

  public RegulatedAuthorizationUvEpi set_case(BackboneElement value) {
    this._case = value;
    return this;
  }
  public boolean has_case() {
    return _case != null;
  }



  public void clear() {
    id = null;
    extensions.clear();
    modifierExtensions.clear();
    identifiers.clear();
    subjects.clear();
    validityPeriod = null;
    indications.clear();
    holder = null;
    regulator = null;
    attachedDocuments.clear();
    _case = null;

  }

}
